package com.xjscrm.console.vo;

import com.github.pagehelper.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

@Data
public class MyPageInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int current;
    private int size;
    private long total;
    private int pages;
    private List<T> records;

    public MyPageInfo(List<T> records) {
        this(records, 8);
    }

    public MyPageInfo(List<T> records, int navigatePages) {
        if (records instanceof Page) {
            Page page = (Page) records;
            this.current = page.getPageNum();
            this.size = page.getPageSize();
            this.pages = page.getPages();
            this.records = page;
            this.total = page.getTotal();
        } else if (records instanceof Collection) {
            this.current = 1;
            this.size = records.size();
            this.pages = this.size > 0 ? 1 : 0;
            this.records = records;
            this.total = records.size();
        }

    }
}
